package javabase.collection.list.search;

import java.text.CollationKey;
import java.text.Collator;
import java.util.Locale;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * <pre>
 *   Title: Person.java
 *   Description: 
 *   Copyright: yundaex.com Copyright (c) 2013
 *   Company: 上海韵达货运有限公司
 * </pre>
 * 
 * @author liuzhaoqing
 * @version 1.0
 * @date 2014年11月6日
 */
public class Person implements Comparable<Person> {

	  private String fullName;
	  private String duties;
	  private int salary;

	  public Person(String fullName, String duties, int salary) {
		this.fullName = fullName;
		this.duties = duties;
		this.salary = salary;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public int getSalary() {
		return salary;
	}

	public void setSalary(int salary) {
		this.salary = salary;
	}

	public String getDuties() {
		return duties;
	}

	public void setDuties(String duties) {
		this.duties = duties;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((duties == null) ? 0 : duties.hashCode());
		result = prime * result + ((fullName == null) ? 0 : fullName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (duties == null) {
			if (other.duties != null)
				return false;
		} else if (!duties.equals(other.duties))
			return false;
		if (fullName == null) {
			if (other.fullName != null)
				return false;
		} else if (!fullName.equals(other.fullName))
			return false;
		return true;
	}

	@Override
	  public String toString() {
	    return ToStringBuilder.reflectionToString(this);
	  }

	public int compareTo(Person per) {
		Collator zhCollator = Collator.getInstance(Locale.CHINA);
		CollationKey[] keys = new CollationKey[4];
		keys[0] = zhCollator.getCollationKey(this.getFullName());
		keys[1] = zhCollator.getCollationKey(per.getFullName());
		keys[2] = zhCollator.getCollationKey(per.getDuties());
		keys[3] = zhCollator.getCollationKey(per.getDuties());
		int tmp = 0;
		if ((tmp = keys[0].compareTo(keys[1])) != 0) {
			return tmp;
		} else {
			if ((tmp = keys[0].compareTo(keys[1])) != 0) {
				return tmp;
			}
			return 0;
		}
	}
}
